// SYOA Javascript framework

//加入到收藏
function addBookmark(title,url) {
    if (window.sidebar) {   
        window.sidebar.addPanel(title, url,"");   
    } else if( document.all ) {  
        window.external.AddFavorite( url, title);  
    } else if( window.opera && window.print ) {  
        return true;  
    }  
}

//标准弹出框
var dialog = null;
function SYalert(msg,size)
{
	var div = document.getElementById('_dialog');
	if(div == null)
	{
		div = document.createElement('div');
		div.id = '_dialog';
		div.title = '协作平台提醒您';
		//div.style = 'font-size:12px;';
		document.body.appendChild(div);
	}
	div.innerHTML = '<font size='+size+'>'+msg+'</font>';	
	if(dialog == null)
	{
		dialog = $(function() {
			$("#_dialog").dialog({
				bgiframe: true,
				resizable: false,
				height:150,
				modal: true,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				},
				buttons: {
					'OK': function() {
						$(this).dialog('close');
					}
				}
			});
		});
	}else
	{
		$("#_dialog").dialog('open');
	}
}

//标准确认框
var conf;
function SYconfirm(msg,callback)
{
	var div = document.getElementById('_conf');
	if(div == null)
	{
		div = document.createElement('div');
		div.id = '_conf';
		div.title = 'SY企业协作平台';
		document.body.appendChild(div);
	}
	div.innerHTML = msg+'<br /><input type="text" id="_conftext" value="" name="_conftext" />';	
	if(conf == null)
	{
		conf = $(function() {
			$("#_conf").dialog({
				bgiframe: true,
				resizable: false,
				height:180,
				modal: true,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				},
				buttons: {
					'确认': function() {
						$(this).dialog('close');
						var input = document.getElementById('_conftext').value;
						callback.callback(input);	
					},
					'取消': function() {
						$(this).dialog('close');
					}						
				}
			});
		});
	}else
	{
		$("#_conf").dialog('open');
	}		
}

//封装进度条
var prog;
function SYProgress(msg)
{
	var div = document.getElementById('_prog');
	if(div == null)
	{
		div = document.createElement('div');
		div.id = '_prog';
		div.title = 'SYOA协作平台';

		document.body.appendChild(div);
	}
	div.innerHTML = '<p align="center"><img src="/skin/default/images/large-loading.gif" />'+msg+'</p>';	
	if(prog == null)
	{
		prog = $(function() {
			$("#_prog").dialog({
				bgiframe: true,
				resizable: false,
				height:140,
				modal: true,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				}
			});
		});
	}else
	{
		$("#_prog").dialog('open');
	}		
}

//关闭进度条
function closeProgress()
{
	$('#_prog').dialog('close');
}

function getCookieVal (offset)
{
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
  endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
//去除字符串左侧空格
function ltrim(s){
    return s.replace( /^\s*/, "");
}
//去除字符串右侧空格
function rtrim(s){
    return s.replace( /\s*$/, "");

}
//去除字符串左右两侧空格
function trim(s){
    return rtrim(ltrim(s));
}
//判断字符串是否为空值
function IsEmpty(_str){
    var tmp_str = trim(_str);
    return tmp_str.length == 0;
}